<?php
class ProductType extends AppModel {
	var $name = 'ProductType';
	var $primaryKey  = 'id';
	var $useTable = "product_types";

	function get($id) {
		return $this->find('first', array(
			'conditions' => array(
				'id' => $id
		)));
	}


	/**
	 * tạo cây nhóm sản phẩm ...
	 * @return array
	 */
	 /*--------------------Start get tree--------------------*/
	function getList() {
		
		$list = null;
		$items = $this->find('all');
		$this->genTreeList($items, $list);
		
		return $list;
	}

	private function genTreeList($items, &$list, $spec='', $parent=0) {
		$_child = false;
		if($parent == 0) {
			$spec = '';
		} else {
			$spec .= '----';
		}
		foreach($items as $r) {
			if($r[$this->alias]['parent'] == $parent) {
				$_child = true;
				$list[$r[$this->alias]['id']] = $spec . $r[$this->alias]['name_vie'];
				$_child = $this->genTreeList($items, $list, $spec, $r[$this->alias]['id']);
			}
		}
		return $_child;
	}
	 /*--------------------End get tree--------------------*/
}
?>